<template>
  <div class="app-container">
    <el-row type="flex">
      <el-input
        v-model="input"
        style="width: 300px"
        placeholder="请输入搜索内容"
        class="input-with-select"
        @input="handlerInput"
      >
        <el-button slot="append" icon="el-icon-search"/>
      </el-input>
    </el-row>

    <el-table
      style="margin-top: 10px"
      :data="showList"
      element-loading-text="Loading"
      border
      fit
      highlight-current-row
    >
      <el-table-column align="center" label="房源名称">
        <template slot-scope="scope">
          <router-link :to="`/house/detail/${scope.row.id}`">
            <el-row style="color:#1890FF;font-weight: 600; ">{{ `${scope.row['city']}${scope.row['address']}${scope.row['detailAddress']}` }}</el-row>
          </router-link>
        </template>
      </el-table-column>
      <el-table-column label="房源图片" align="center">
        <template slot-scope="scope">
          <el-image :src="scope.row.photo"></el-image>
        </template>
      </el-table-column>
      <!--      <el-table-column label="用户名" align="center">-->
      <!--        <template slot-scope="scope">-->
      <!--          <span>{{ scope.row['1'] }}</span>-->
      <!--        </template>-->
      <!--      </el-table-column>-->
      <!--      <el-table-column label="上架时间" align="center">-->
      <!--        <template slot-scope="scope">-->
      <!--          <span>{{ scope.row[2] }}</span>-->
      <!--        </template>-->
      <!--      </el-table-column>-->
      <el-table-column label="月租金" align="center">
        <template slot-scope="scope">
          {{ scope.row['price'] }}
        </template>
      </el-table-column>
      <el-table-column label="举报理由" align="center">
        <template slot-scope="scope">
          {{ scope.row['conversation'] }}
        </template>
      </el-table-column>
      <el-table-column class-name="status-col" label="操作" align="center">
        <template slot-scope="scope">
          <el-button size="small" type="danger" @click="modifyReportStatusFail(scope.row)">举报无效</el-button>
          <el-popconfirm
            title="举报有效，确定下架该房源吗？"
            @confirm="modifyReportStatusSuccess(scope.row)"
          >
            <el-button slot="reference" size="small" type="success">举报有效</el-button>
          </el-popconfirm>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      :page-size.sync="query.pageSize"
      :current-page.sync="query.current"
      :page-sizes="[10,20,50,100]"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
      @current-change="getReportList"
      @size-change="getReportList"
    />
  </div>
</template>

<script>
import { parseTime } from '@/utils'
import { getReportList, modifyReportStatus } from '@/api/report'
import { offHouse } from '@/api/house'

export default {
  filters: {
    parseTime
  },
  data() {
    return {
      currentPage: 1,
      input: '',
      query: {
        current: 1,
        pageSize: 10
      },
      total: 0,
      list: [],
      showList: [],
      reportList: [],
      status: {
        '0': '待审核',
        '1': '举报成功',
        '-1': '举报失败'
      }
    }
  },

  created() {
    this.getReportList()
  },
  methods: {
    async modifyReportStatusSuccess(row) {
      const res = await modifyReportStatus({
        reportId: row.reportId,
        status: 1
      })
      const res2 = await offHouse({
        houseId: row.id
      })
      console.log(res, res2)
      if (res.code !== 1) return this.$message.error(res.message)
      this.$message.success(res.message)
      this.getReportList()
    },
    async modifyReportStatusFail(row) {
      const res = await modifyReportStatus({
        reportId: row.reportId,
        status: -1
      })
      if (res.code !== 1) return this.$message.error(res.message)
      this.$message.success(res.message)
      this.getReportList()
    },
    async getReportList() {
      const res = await getReportList(this.query)
      console.log(res)
      if (res.code !== 1) return this.$message.error(res.message)
      this.total = res.data.total
      this.reportList = this.showList = res.data.list
    },
    handlerInput() {

    }

  }
}
</script>
